package logic

import (
	"context"
	"errors"
	"goods_srv/goods"
	"goods_srv/internal/svc"
	"goods_srv/models/mysqlinit"

	"github.com/zeromicro/go-zero/core/logx"
)

type StatusHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStatusHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusHouseLogic {
	return &StatusHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StatusHouseLogic) StatusHouse(in *goods.StatusHouseRequest) (*goods.StatusHouseResponse, error) {
	// todo: add your logic here and delete this line

	var houses mysqlinit.House
	mysqlinit.DB.Debug().Where("user_id = ?", in.UserId).Find(&houses)
	if houses.UserId != int(in.UserId) {
		logx.Error("无法上架他人房源状态")
		return nil, errors.New("无法上架他人房源状态")
	}
	house := mysqlinit.House{

		Status: in.Status,
	}
	mysqlinit.DB.Debug().Where("id = ?", in.Id).Updates(&house)
	return &goods.StatusHouseResponse{
		Id: int64(houses.ID),
	}, nil
}
